/*


 */

package jas.http.request;

import java.io.IOException;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;

/**
 *
 *
 */
public class HttpRequest {
    
    private String method;
    private String path;
    private String version;
    private String body;
    private Map<String, String> headers = new HashMap<String, String>();
    
    public HttpRequest() {
        
    }
    
    public void setHeader(String name, String value) {
        headers.put(name, value);
    }
    
    public String getRequestLine() {
        return getMethod() + " " + getPath() + " " + getVersion();
    }

    public String getMethod() {
        return method;
    }

    public String getPath() {
        return path;
    }

    public String getVersion() {
        return version;
    }

    public String getBody() {
        return body;
    }
    
    public String getHeader(String name) {
        return headers.get(name);
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    public void setBody(String body) {
        this.body = body;
    }
    
    public void print(OutputStream output) throws IOException {
        String requestLine = method + " " + path + " " + version + "\r\n";
        System.out.println("Printing request: " + requestLine);
        String headerString = "";
        for (String headerName : headers.keySet()) {
            headerString += headerName + ": " + headers.get(headerName) + "\r\n";
        }
        String entireRequest = requestLine + headerString + "\r\n" + body;
        output.write( entireRequest.getBytes() );
    }
    
}
